<template>
  <div>
    <div class="floor-wrap">
      <div>
        <div class="floor-item" v-for="item of floorList" :key="item.id">
          <el-button @click="floorChange(item)" :class="{ active: selectFloor == item.id }">
            {{ item.name }}
          </el-button>
        </div>
      </div>
      <div class="date-wrap">
        <div class="date-item" v-for="item of dateList" :key="item.date">
          <el-button @click="dateChange(item)" :class="{ active: nowMonthDay == item.date }">
            {{ item.date }} {{ item.week }}
          </el-button>
        </div>
      </div>
    </div>

    <div class="seminar-wrap">
      <div class="seminar-list">
        <div class="seminar-item" v-for="item of seminarList" :key="item.id">
          <div class="item-header">
            <div>
              <span class="room-name">房间名称：{{ item.name }}</span>
              <span class="room-num">人数：{{ item.capacity }}</span>
              <span class="room-info">
                <el-popover placement="bottom" width="500" trigger="click">
                  <el-descriptions :title="item.name">
                    <el-descriptions-item label="可容纳人数">
                      {{ item.capacity }}
                    </el-descriptions-item>
                    <el-descriptions-item label="研讨室位置">
                      {{ item.location }}
                    </el-descriptions-item>
                    <el-descriptions-item label="负责人">{{ item.principal }}</el-descriptions-item>
                    <el-descriptions-item label="办公室">{{ item.office }} </el-descriptions-item>
                    <el-descriptions-item label="联系方式">{{ item.phone }} </el-descriptions-item>
                    <el-descriptions-item label="联系邮箱">{{ item.email }} </el-descriptions-item>
                    <el-descriptions-item label="设备" :span="3">
                      {{ item.equipment }}
                    </el-descriptions-item>
                    <el-descriptions-item label="规则" :span="3">
                      {{ item.rule }}
                    </el-descriptions-item>
                  </el-descriptions>
                  <el-button type="info" size="mini" slot="reference"> 房间信息 </el-button>
                </el-popover>
              </span>
            </div>
            <div>
              <el-button size="small" type="primary" @click="reservation(item)">预约</el-button>
            </div>
          </div>
          <div class="item-time-line">
            <time-line :chooseDate="nowDate" :ref="`timeLine${item.id}`"></time-line>
          </div>
        </div>
      </div>
    </div>
    <seminar-res ref="reservation"></seminar-res>
  </div>
</template>

<script>
import request from '@/req'
import dayjs from 'dayjs'
import TimeLine from '../components/TimeLine.vue'
import seminarRes from './seminar-res.vue'
dayjs.locale('zh-cn')
export default {
  components: { TimeLine, seminarRes },
  data() {
    return {
      lidId: this.$route.params.id,
      floorList: [],
      dateList: [],
      nowDate: dayjs().format('YYYY-MM-DD'),
      selectFloor: '',
      nowMonthDay: dayjs().format('MM月DD日'),
      readingRoomList: [],
      seminarList: [],
    }
  },
  async created() {
    await this.getFloorListByLibId()
    this.getSeminarRoomListByFloorId()

    this.dateList.push({
      date: dayjs().format('MM月DD日'),
      week: '今天',
      ymd: dayjs().format('YYYY-MM-DD'),
    })
    this.dateList.push({
      date: dayjs().add(1, 'day').format('MM月DD日'),
      week: dayjs().add(1, 'day').format('ddd'),
      ymd: dayjs().add(1, 'day').format('YYYY-MM-DD'),
    })
    this.dateList.push({
      date: dayjs().add(2, 'day').format('MM月DD日'),
      week: dayjs().add(2, 'day').format('ddd'),
      ymd: dayjs().add(2, 'day').format('YYYY-MM-DD'),
    })
  },
  mounted() {},
  methods: {
    async getFloorListByLibId() {
      const res = await request.get(`/floor/getFloorListByLibId?libId=${this.lidId}`)
      this.floorList = res ? res : []
      this.selectFloor = res[0].id
    },
    async getSeminarRoomListByFloorId() {
      const res = await request.get(
        `/seminarRoom/getSeminarRoomListByFloorId?floorId=${this.selectFloor}`
      )
      this.seminarList = res ? res : []
    },
    dateChange(date) {
      this.nowMonthDay = date.date
      this.nowDate = date.ymd
    },
    floorChange(floor) {
      this.selectFloor = floor.id
      this.nowMonthDay = this.dateList[0].date
      this.nowDate = this.dateList[0].date.ymd
      this.getSeminarRoomListByFloorId()
    },
    reservation(room) {
      const user = sessionStorage.getItem('user')
      if (!user) {
        this.$message({
          type: 'warning',
          message: '请先登录再预约',
        })
        return
      }
      const resTimes = this.$refs[`timeLine${room.id}`][0].getTimeVal()
      this.$refs.reservation.openDia(room, this.nowDate, resTimes[0], resTimes[1])
    },
    showInfo(data) {},
  },
}
</script>

<style scoped>
.floor-wrap {
  position: absolute;
  top: 30%;
  margin-left: 20px;
  display: flex;
  flex-direction: row;
}

.date-wrap {
  margin-left: 8px;
}
.floor-item,
.date-item {
  margin-bottom: 10px;
}

.seminar-wrap {
  border-left: 1px solid #ccc;
  height: calc(100vh - 50px);
  overflow-y: scroll;
  margin-left: 250px;
  padding: 10px 20px;
  width: calc(100vw - 250px);
}

.seminar-item {
  border: 1px solid #ccc;
  border-radius: 8px;
  padding-bottom: 10px;
  margin-bottom: 15px;
}

.item-header {
  margin-bottom: 15px;
  background-color: #eee;
  padding: 10px;
  border-top-left-radius: 8px;
  border-top-right-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.item-time-line {
  padding: 0 20px;
}

.room-name {
  font-size: 18px;
  font-weight: 600;
}
.room-info {
  margin-left: 10px;
  cursor: pointer;
}
.room-num {
  margin-left: 15px;
}
.active {
  color: #409eff;
  border-color: #c6e2ff;
  background-color: #ecf5ff;
}
</style>
